# 定期清除文件
import os.path
import time
import fitz


path = os.path.join('static/media')
files = os.listdir(path)
for file_name in files:
    if not file_name.endswith('.media'):
        continue
    f_path = os.path.join('static/media', file_name)
    timestamp = os.path.getctime(f_path)
    current_timestamp = time.time()
    if current_timestamp - timestamp > 86400:
        os.remove(f_path)
        print(f_path + " 已经移除")
    else:
        time_readable = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
        print('创建时间：' + time_readable)
